package com.hangzhou.xyj.ui.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.hangzhou.xyj.ui.fragment.FindActionItemFragment;

/**
 * 发现->活动 适配器
 * <p/>
 * Created by Administrator on 2016/1/15.
 */
public class FindActionAdapter extends FragmentPagerAdapter {
    private final String[] mTitles = {
            "全国",
            "同城",
            "票友",
    };

    private FindActionItemFragment mCountryFragment;
    private FindActionItemFragment mCityFragment;
    private FindActionItemFragment mFriendsFragment;

    public FindActionAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        //创建一个Bundle，用于传递数据
        Bundle bundle = new Bundle();
        switch (position) {
            case 0:
                if (mCountryFragment == null)
                    mCountryFragment = new FindActionItemFragment();
                bundle.putInt("scopeType", FindActionItemFragment.SCOPE_TYPE_COUNTRY);
                mCountryFragment.setArguments(bundle);
                return mCountryFragment;
            case 1:
                if (mCityFragment == null)
                    mCityFragment = new FindActionItemFragment();
                bundle.putInt("scopeType", FindActionItemFragment.SCOPE_TYPE_CITY);
                mCityFragment.setArguments(bundle);
                return mCityFragment;
            case 2:
            default:
                if (mFriendsFragment == null) {
                    mFriendsFragment = new FindActionItemFragment();
                }
                bundle.putInt("scopeType", FindActionItemFragment.SCOPE_TYPE_FRIENDS);
                mFriendsFragment.setArguments(bundle);
                return mFriendsFragment;
        }
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
    }
}
